<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org" lang="en">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta name="viewport"
          content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no"/>
    <title>个人理财系统</title>
    <!-- 引入bootstrap样式 -->
    <link th:href="@{/bootstrap/css/bootstrap.css}" rel="stylesheet" type="text/css">
    <!--图标库-->
    <link th:href="@{/lyear/css/materialdesignicons.min.css}" rel="stylesheet" type="text/css"/>
    <!--弹出框样式-->
    <link th:href="@{/lyear/jconfirm/jquery-confirm.min.css}" rel="stylesheet" type="text/css"/>
    <!--自定义样式-->
    <link href="../lyear/css/style.min.css" th:href="@{/lyear/css/style.min.css}" rel="stylesheet" type="text/css"/>

</head>
<body>
<div class="lyear-layout-web">
    <div class="lyear-layout-container">
        <!--左侧导航-->
        <div th:replace="user/common/leftbar::#leftbaraside"></div>
        <!--头部信息-->
        <div th:replace="user/common/topbar::#topbarheader"></div>

        <!--页面主要内容-->
        <main class="lyear-layout-content">
            <div class="container-fluid">
                <div class="row">
                    <div class="col-lg-12">
                        <div class="card">
                            <div class="card-header">
                                <h4>工资理财推荐</h4>
                            </div>
                            <div th:if="${!payMoneyList.isEmpty()}" class="card-body">
                                <div class="table-responsive">
                                    <table class="table table-hover table-striped">
                                        <thead>
                                        <tr>
                                            <th class="info">序号</th>
                                            <th class="info">产品类型</th>
                                            <th class="info">每月金额设定</th>
                                            <th class="info">自动转入</th>
                                            <th class="info">投资期限</th>
                                            <th class="info">相关操作</th>
                                        </tr>
                                        </thead>
                                        <tbody>
                                        <tr th:each="pm:${payMoneyList}">
                                            <td th:text="${pmStat.index+1}"></td>
                                            <td th:if="${pm.type==1}" th:text="国债"></td><td th:if="${pm.type==2}" th:text="期货"></td>
                                            <td th:text="${#numbers.formatDecimal(pm.monthmoney,1,2)}"></td>
                                            <td th:if="${pm.autointo==1}" th:text="是"></td><td th:if="${pm.autointo==2}" th:text="否"></td>
                                            <td th:text="${pm.investerm}"></td>
                                            <td>
                                                <button class="btn btn-primary btn-sm buy_btn"
                                                        th:attr="buyBtnId=${pm.id},buyBtnName=${pm.type}">
															<span class="glyphicon glyphicon-usd"
                                                                  aria-hidden="true"></span> 投资
                                                </button>
                                            </td>
                                        </tr>
                                        </tbody>
                                    </table>
                                </div>
                            </div>

                            <div th:if="${payMoneyList.isEmpty()}" class="card-body">
                                <div class="table-responsive">
                                    <h4>很抱歉！暂时还没有工资理财向您推荐</h4>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </main>
        <!--End 页面主要内容-->
    </div>
</div>

<!-- 引入jQuery和bootstrap的js -->
<script th:src="@{/js/jquery.js}"></script>
<script th:src="@{/bootstrap/js/bootstrap.js}"></script>
<!--滚动条插件-->
<script th:src="@{/lyear/js/perfect-scrollbar.min.js}"></script>
<!--弹出框js-->
<script th:src="@{/lyear/jconfirm/jquery-confirm.min.js}"></script>
<!--自定义js脚本-->
<script th:src="@{/lyear/js/main.min.js}"></script>
<script th:inline="javascript">
    $(document).on("click",".buy_btn",function () {
        var payMoneyId = $(this).attr("buyBtnId");
        var userId = [[${session.loginUser.id}]];
        //alert(userId);
        var type = $(this).attr("buyBtnName");
        var name;
        if (type==1){
            name="国债"
        }else{
            name="期货";
        }
        $.alert({
            title: '提示：',
            content: "确定买入该 <strong>"+name+"</strong> 吗？",
            buttons: {
                confirm: {
                    text: '确认',
                    btnClass: 'btn-primary',
                    action: function(){
                        $.ajax({
                            url : "/user/buyPayMoney",
                            type : "POST",
                            data : {
                                "payMoneyId":payMoneyId,
                                "userId":userId
                            },
                            success : function(result) {
                                if (result.code===100){
                                    $.alert('买入成功!');
                                }else {
                                    $.alert('买入失败!');
                                }
                            }
                        });

                    }
                },
                cancel: {
                    text: '取消',
                    action: function () {
                        $.alert('已取消!');
                    }
                }
            }
        });
    })

</script>
</body>
</html>
